package com.stedu.service.impl;

import com.stedu.bean.Teacher;
import com.stedu.mapper.TeacherAndStudentMapper;
import com.stedu.service.TeacherAndStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TeacherAndStudentServiceImpl implements TeacherAndStudentService {
    @Autowired
    private TeacherAndStudentMapper teacherAndStudentMapper;

    @Override
    public List<Teacher> selectAll() {
        return teacherAndStudentMapper.selectAll();
    }

    @Override
    public List<Integer> selectSidByTid(Integer tid) {
        return teacherAndStudentMapper.selectSidByTid(tid);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)//加回滚
    public void InsertTidAndSid(Integer tid, Integer[] sids) {
        //删除关联关系
        teacherAndStudentMapper.deleteTidAndSidByTid(tid);
        //添加关联关系
        if (sids != null && sids.length >0) {
            teacherAndStudentMapper.InsertTidAndSid(tid, sids);
        }
    }
}
